﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RollBackLib.src.core
{
    /// <summary>
    /// Represents a single SMTP Entry
    /// </summary>
    public class SMTPEntry
    {
        public string m_ServerName
        {
            get;
            set;
        }

        public string m_ServerPort
        {
            get;
            set;
        }

        public string m_useSSL
        {
            get;
            set;
        }

        public string getKey()
        {
            string str = m_ServerName +":" + m_ServerPort;
            return str;
        }

        public SMTPEntry()
        {
        }

        public SMTPEntry(string serverName, string serverPort, string useSSL)
        {
            m_ServerName = serverName;
            m_ServerPort = serverPort;
            m_useSSL = (useSSL.Equals("true", StringComparison.CurrentCultureIgnoreCase)) ? "True" : "False";
        }
    }


    /// <summary>
    /// Represents the SMTP Table which can serialized and de-serialized into an XML file.
    /// </summary>
    public class SMTPTable
    {
        public List<SMTPEntry> m_smtpList = new List<SMTPEntry>();

        /// <summary>
        /// Get the SMTP entry by id (host+port).  Return null if not found.
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public SMTPEntry getById(string p)
        {
            foreach (SMTPEntry e in m_smtpList)
            {
                if (p.Equals(e.getKey(), StringComparison.InvariantCultureIgnoreCase))
                {
                    return e;
                }
            }
            return null;
        }

        /// <summary>
        /// Add the SMTPEntry to the internal table
        /// </summary>
        /// <param name="e"></param>
        internal void add(SMTPEntry e)
        {
            m_smtpList.Add(e);
        }
    }
}
